package com.lcredu.seckill.config;

import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author 黎长容
 * @date 2025-09-13 15:08
 */
@Component
public class RabbitMQInitializer {
    
    @Resource
    private AmqpAdmin amqpAdmin;
    
    @PostConstruct
    public void clearQueues(){
        if (amqpAdmin != null && RabbitSeckillMessageConfig.SECKILLMESSAGEQUEUE != null) {
            amqpAdmin.purgeQueue(RabbitSeckillMessageConfig.SECKILLMESSAGEQUEUE, true);
            System.out.println("已清空秒杀消息队列: " + RabbitSeckillMessageConfig.SECKILLMESSAGEQUEUE);
        }
    }
}
